<!--参保档案-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'attendance:shift:save'" type="primary" @click="addOrUpdateHandle()">导入</el-button>
				<el-button v-auth="'attendance:shift:save'" type="primary" @click="addOrUpdateHandle()">导出</el-button>
			</el-form-item>

			<el-form-item label="职位">
				<el-tree-select
					v-model="state.queryForm.carTypeId"
					:data="queryList"
					value-key="id"
					check-strictly
					clearable
					:render-after-expand="false"
					:props="{ value: 'id', label: 'name', children: 'children' }"
					style="width: 100%"
				/>
			</el-form-item>
			<el-form-item label="入职日期">
				<el-date-picker 
					v-model="state.queryForm.timeDate" 
					type="daterange"
					range-separator="~"
					start-placeholder="请选择日期"
					end-placeholder="请选择日期"
				/>
			</el-form-item>
			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>

		<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

			<el-table-column prop="name" label="员工" header-align="center" align="center"></el-table-column>
			<el-table-column prop="code" label="工号" header-align="center" align="center"></el-table-column>
			<el-table-column prop="organName" label="员工部门" header-align="center" align="center"></el-table-column>
			<el-table-column prop="phone" label="员工职位" header-align="center" align="center"></el-table-column>
			<el-table-column prop="phone" label="员工类型" header-align="center" align="center"></el-table-column>

			<el-table-column prop="phone" label="员工状态" header-align="center" align="center"></el-table-column>
			<el-table-column prop="phone" label="社保参保状态" header-align="center" align="center"></el-table-column>
			<el-table-column prop="phone" label="公积金参保状态" header-align="center" align="center"></el-table-column>

			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'staff:staff:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">投保</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

	</el-card>
</template>

<script setup lang="ts" name="StaffStaffIndex">
import { useCrud } from '@/hooks'
import { Ref, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'

import { findAll } from '@/api/nb/organization/position'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'
import { findAll as findJobLevel } from '@/api/nb/organization/position/level'
import { findAllApi } from '@/api/nb/organization/workplace'

const queryList = ref()
const state: IHooksOptions = reactive({
	dataListUrl: '/nb/staff/page',
	deleteUrl: '/nb/staff',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

// 获取职位
const positionList = ref()
const getPosition = () => {
	return findAll().then(res => {
		positionList.value = res.data
	})
}
getPosition()

// 获取职务
const ziWuList = ref()
const getDictList = (code: String, list: Ref) => {
	findListByDictId({ params: { code: code } }).then(res => {
		list.value = res.data
	})
}
getDictList('ZhiWu', ziWuList)

// 获取 所属职级
const jobLevelList = ref()
const getJobLevelList = () => {
	return findJobLevel().then(res => {
		jobLevelList.value = res.data
	})
}
getJobLevelList()

// 获取 工作地点
const workplaceList = ref()
const getWorkplace = () => {
	return findAllApi().then(res => {
		workplaceList.value = res.data
	})
}
getWorkplace()

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
